import Router from '@koa/router'
import NA from '../lib/nami.js'

const nm = new NA()

export default app => {
  const router = new Router()

  router.post('/nami', async ctx => {
    const { message } = ctx.request.body

    if (!message) throw '消息不能为空'

    const result = await nm.chat(message)

    ctx.body = {
      code: 0,
      data: {
        result,
      },
    }
  })

  app.use(router.routes()).use(router.allowedMethods())
}
